package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONArray;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.enums.PlatformEnum;
import com.ymatou.iapi.trading.operate.parameter.req.OrderPostPayRequestBean;
import com.ymatou.iapi.trading.operate.service.OrderPostPayRequestCall;
import com.ymatou.operate.trading.api.parameter.PlaceOrderBean;
import com.ymatou.operate.trading.api.service.PlaceOrderCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.AccountCallService;
import com.ymttest.business.service.CouponCallService;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.business.service.ProductCallService;
import com.ymttest.common.entitie.OrderInfo;
import com.ymttest.common.entitie.OrderProductInfo;
import com.ymttest.common.entitie.ProductActivityInfo;
import com.ymttest.common.enums.ActivityPromotionTypeEnum;
import com.ymttest.common.enums.AppTerminalSourceEnum;
import com.ymttest.common.enums.BondedAreaEnum;
import com.ymttest.common.enums.LogisticsTypeEnum;
import com.ymttest.common.enums.OrderSourceEnum;
import com.ymttest.common.enums.OrderTypeEnum;
import com.ymttest.common.enums.PriceTypeEnum;
import com.ymttest.common.enums.ProductRefundChannelEnum;
import com.ymttest.common.enums.StockStatusEnum;
import com.ymttest.common.enums.TerminalSourceEnum;
import com.ymttest.database.model.YmtAccountEntry;
import com.ymttest.database.mongo.YMatouSellerOrderWapper;
import com.ymttest.database.sqlwapper.AccountDefaultWapper;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 新增订单补款接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_OrderPostPayRequest {
    private static OrderPostPayRequestBean orderpostpayrequestbean;

    private static OrderPostPayRequestCall orderpostpayrequestcall;

    @BeforeClass
    public static void setUp() {
        Logger.createResultFile("新订单补款接口");
    }

    @Before
    public void caseUp() {
        orderpostpayrequestbean = new OrderPostPayRequestBean();
        orderpostpayrequestcall = new OrderPostPayRequestCall();
    }

    @AfterClass
    public static void tearDown() {
        Logger.generateResult(orderpostpayrequestcall.getOpurl());
    }

    @After
    public void caseDown() {
        Logger.end();
    }

    /**
     * 验证alipayapp 返回
     * 
     * @param orderId
     * @throws Exception
     */
    private void verifyAlipayApp(int orderId) throws Exception {
        Logger.comment("验证支付宝APP Result报文");
        // 订单主表
        List<Map> ymtOrders = new DefaultWapper().selectOrderByOderId(orderId);

        List<Map> ymtOrderPostPay = new DefaultWapper().selectOrderPostPayByOrderId(orderId);

        // 第三方支付的金额=订单补款金额-使用余额支付的金额
        // 申请补款的金额
        BigDecimal postPayAmount = (BigDecimal) ymtOrderPostPay.get(0).get("fAmount");
        BigDecimal totalFee = postPayAmount.subtract(orderpostpayrequestbean.getUseAccountAmount());
        String productName = (String) ymtOrders.get(0).get("sBuyerLoginId") + "的订单";

        Map m = (Map) FormatUtil.GSONToObject(orderpostpayrequestcall.getData().getString("result"), Map.class);
        Logger.verifyNotNull(m.get("Sign"), "验证Sign非空");
        Logger.verifyEquals("2088701734809577", m.get("Partner"), "验证partner合作者身份ID");
        Logger.verifyEquals("ap.ymt@ymatou.com", m.get("SellerId"), "验证SellerId买家支付宝账号");
        // 查询第三方支付流水
        List<Map> postPayTradingId = new DefaultWapper().queryPostPayTradingInfoAndPayment(orderId);

        String trandno = (String) postPayTradingId.get(0).get("PaymentId");
        Logger.verifyEquals(trandno, m.get("OutTradeNo"), "验证OutTradeNo");
        Logger.verifyEquals(productName, m.get("Subject"), "验证Subject");
        Logger.verifyEquals(true,
                TestDataManager.equalsBigDecimal(new BigDecimal(m.get("TotalFee").toString()), totalFee.toString()),
                "验证total_fee:" + m.get("TotalFee"));
        if (EnvSetup.getEnv().equals("sit1")) {
            Logger.verifyEquals(
                    "http://" + "sit" + ".payment.ymatou.com:8380/notify/"
                            + orderpostpayrequestbean.getPayType(),
                    m.get("NotifyUrl"), "验证NotifyUrl");
        }
        else if (EnvSetup.getEnv().equals("uat")) {
            Logger.verifyEquals(
                    "http://" + "uat" + ".payment.ymatou.com:8480/notify/"
                            + orderpostpayrequestbean.getPayType(),
                    m.get("NotifyUrl"), "验证NotifyUrl");
        }

        Logger.verifyEquals("mobile.securitypay.pay", m.get("Service"), "验证Service");
        Logger.verifyEquals("1", m.get("PaymentType"), "验证PaymentType");
        Logger.verifyEquals("utf-8", m.get("InputCharset"), "验证InputCharset");
        Logger.verifyEquals("10d", m.get("ItBPay"), "验证ItBPay");
        Logger.verifyEquals("RSA", m.get("SignType"), "验证SignType");
        Logger.verifyEquals(true, m.get("QuerySuccess"), "验证QuerySuccess");
        Logger.verifyEquals("成功", m.get("Message"), "验证Message");
        Logger.comment("验证EncryptStr");
        Map mencrypt = FormatUtil.httpStringToMap(m.get("EncryptStr").toString());
        Logger.verifyNotNull(mencrypt.get("sign"), "验证Sign非空");
        Logger.verifyEquals("2088701734809577", mencrypt.get("partner"), "验证partner合作者身份ID");
        Logger.verifyEquals("ap.ymt@ymatou.com", mencrypt.get("seller_id"), "验证seller_id买家支付宝账号");
        Logger.verifyEquals(trandno, mencrypt.get("out_trade_no"), "验证out_trade_no");
        Logger.verifyEquals(productName, mencrypt.get("subject"), "验证subject");
        Logger.verifyEquals(
                true,
                TestDataManager.equalsBigDecimal(new BigDecimal(mencrypt.get("total_fee").toString()),
                        totalFee.toString()), "验证total_fee:" + mencrypt.get("total_fee"));
        if (EnvSetup.getEnv().equals("sit1")) {
            Logger.verifyEquals("http://" + "sit" + ".payment.ymatou.com:8380/notify/"
                    + orderpostpayrequestbean.getPayType(), mencrypt.get("notify_url"), "验证notify_url");
        }
        else if (EnvSetup.getEnv().equals("uat")) {
            Logger.verifyEquals("http://" + "uat" + ".payment.ymatou.com:8480/notify/"
                    + orderpostpayrequestbean.getPayType(), mencrypt.get("notify_url"), "验证notify_url");
        }
        Logger.verifyEquals("mobile.securitypay.pay", mencrypt.get("service"), "验证service");
        Logger.verifyEquals("1", mencrypt.get("payment_type"), "验证payment_type");
        Logger.verifyEquals("utf-8", mencrypt.get("_input_charset"), "验证_input_charset");
        Logger.verifyEquals("10d", mencrypt.get("it_b_pay"), "验证it_b_pay");
        Logger.verifyEquals("RSA", mencrypt.get("sign_type"), "验证sign_type");
        Logger.verifyEquals("m.alipay.com", mencrypt.get("show_url"), "验证show_url");
        Logger.verifyNotNull(mencrypt.get("sign"), "验证sign非空");
    }

    @Test
    @Category(P1.class)
    @TestCase
    public void Tc_OrderPostPayRequest_001() {
        Logger.start(true, "通过余额支付补款订单,成功");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            new OrderCallService().acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price = 1 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(df.format(price));
            String postPayId = new OrderCallService().applyForPostPay(orderId, sellerId, payAmount);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(payAmount);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            Logger.comment("前置数据准备结束");
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, orderpostpayrequestcall.getCode(), "验证code");
            // 数据库验证
            // 支付后金额
            Thread.sleep(1000);
            
            Map act = new HashMap();
            act.put("bizno", String.valueOf(orderId));
            act.put("userId", userId);         
    		List<YmtAccountEntry> actinfos = new AccountDefaultWapper().selectAccountEntryByBizNo(act);
    		
			BigDecimal accountEntryPrice=actinfos.stream().map(a->a.getAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
    		
            HashMap<String, Integer> m = new HashMap<String, Integer>();
            m.put("OrderId", orderId);
            m.put("TradingStatus", 17);
            m.put("TraddingId", orderId);
            m.put("PaidInFull", 1);
            m.put("UserId", userId);
            Logger.verifyEquals(1, new DefaultWapper().selectOrder(m).size(), "验证订单表记录");
            Logger.verifyEquals(2, new DefaultWapper().selectTradingStatus(m).size(), "验证交易表记录");
            Logger.verifyEquals(totalPrice.add(payAmount), accountEntryPrice.divide(new BigDecimal(-1),2,4), "验证账户资金流水金额");
            Logger.verifyEquals(1, new DefaultWapper().selectOrderPostPayByOrderId(orderId).get(0).get("iAction"),
                    "验证补款Action状态");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P2.class)
    @TestCase
    public void Tc_OrderPostPayRequest_002() {
        Logger.start(true, "输入错误的交易密码，支付失败");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 支付前账户金额
            HashMap<String, Integer> m1 = new HashMap<String, Integer>();
            m1.put("UserId", userId);
            BigDecimal price1 = (BigDecimal) new DefaultWapper().selectAccountInfo(m1).get(0).get("fAvailAmount");
            // 买家付款
            new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            new OrderCallService().acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price = 1 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(df.format(price));
            String postPayId = new OrderCallService().applyForPostPay(orderId, sellerId, payAmount);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId);
            orderpostpayrequestbean.setTradingPwd("errorpwd");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(payAmount);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            Logger.comment("前置数据准备结束");
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.FAILED201, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals(true, orderpostpayrequestcall.getMsg().contains(ECode.FAILED201_MSG_17), "验证msg"
                    + orderpostpayrequestcall.getMsg() + orderpostpayrequestcall.getMsg());
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_003() {
        Logger.start(true, "输入订单号为空，支付失败");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            new OrderCallService().acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price = 1 + new Random().nextInt(50);;
            BigDecimal payAmount = new BigDecimal(df.format(price));
            String postPayId = new OrderCallService().applyForPostPay(orderId, sellerId, payAmount);
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            // orderpostpayrequestbean.setOrderId(123);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(totalPrice);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            Logger.comment("前置数据准备结束");
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.ERROR400, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals(true, orderpostpayrequestcall.getMsg().contains(ECode.ERROR400_MSG_9), "验证msg"
                    + orderpostpayrequestcall.getMsg());
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_004() {
        Logger.start(true, "输入来源ip为空，支付失败");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            new OrderCallService().acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price = 1 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(df.format(price));
            String postPayId = new OrderCallService().applyForPostPay(orderId, sellerId, payAmount);
            Logger.comment("前置数据准备结束");

            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(123);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(totalPrice);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            Logger.comment("前置数据准备结束");
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.ERROR400, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals(true, orderpostpayrequestcall.getMsg().contains(ECode.ERROR400_MSG_7), "验证msg"
                    + orderpostpayrequestcall.getMsg());
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_005() {
        Logger.start(true, "输入支付方式为空，支付失败");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            new OrderCallService().acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price = 1 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(df.format(price));
            String postPayId = new OrderCallService().applyForPostPay(orderId, sellerId, payAmount);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(123);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(totalPrice);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            Logger.comment("前置数据准备结束");
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.ERROR400, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals(true, orderpostpayrequestcall.getMsg().contains(ECode.ERROR400_MSG_8), "验证msg"
                    + orderpostpayrequestcall.getMsg());
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_006() {
        Logger.start(true, "支付金额大于账户剩余金额，支付失败");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 支付
            new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
            // 初始化 修改账户金额为0
            new DefaultWapper().updateAccountInfo(new BigDecimal(0), userId);
            // 接单
            new OrderCallService().acceptOrder(orderId, sellerId);
            BigDecimal postPayAmout = new BigDecimal(100);
            // 卖家申请补款
            String postPayId = new OrderCallService().applyForPostPay(orderId, sellerId, postPayAmout);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = BigDecimal.ZERO;
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(postPayAmout);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            Logger.comment("前置数据准备结束");
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.FAILED201, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals(true, orderpostpayrequestcall
                    .getMsg().contains("账户金额不足"), "验证msg"
                    );
            // 恢复账户金额
            new DefaultWapper().updateAccountInfo(new BigDecimal(999999999), userId);
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_007() {
        Logger.start(true, "此订单不存在");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            new OrderCallService().acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price = 1 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(df.format(price));
            String postPayId = new OrderCallService().applyForPostPay(orderId, sellerId, payAmount);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(1234);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(totalPrice);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            Logger.comment("前置数据准备结束");
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.FAILED201, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals(true, orderpostpayrequestcall.getMsg().contains(ECode.FAILED201_MSG_11), "验证msg"
                    + orderpostpayrequestcall.getMsg());
            // Logger.verifyEquals(ErrorCode.SUCCESSMSG,
            // orderpostpayrequestcall.getMsg(), "验证msg");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_008() {
        Logger.start(true, "当前订单状态不能补款");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            new OrderCallService().acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price = 1 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(df.format(price));
            String postPayId = new OrderCallService().applyForPostPay(orderId, sellerId, payAmount);
            Logger.comment("前置数据准备结束");
            new DefaultWapper().updateTradingStatus(2, orderId);
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(totalPrice);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            Logger.comment("前置数据准备结束");
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.FAILED201, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals(true, orderpostpayrequestcall.getMsg().contains(ECode.FAILED201_MSG_20), "验证msg"
                    + orderpostpayrequestcall.getMsg());
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_009() {
        Logger.start(true, "实际补款金额与申请补款金额不一致");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = new OrderCallService().appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            new OrderCallService().acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price = 1 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(price);
            String postPayId = new OrderCallService().applyForPostPay(orderId, sellerId, payAmount);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            BigDecimal UseAccountAmount = new BigDecimal(1000);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(UseAccountAmount);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            Logger.comment("前置数据准备结束");
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.FAILED201, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals(true, orderpostpayrequestcall.getMsg().contains(ECode.FAILED201_MSG_42), "验证msg");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_010() {
        Logger.start(true, "订单在退货退款中,补款失败");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            Map map = orderService.appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            orderService.orderPayRequest(userId, totalPrice, tradingId);
            // 退货退款同步
            orderService.applySalesRefundRequestInJava(orderId);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            BigDecimal UseAccountAmount = new BigDecimal(1000);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(UseAccountAmount);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            Logger.comment("前置数据准备结束");
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.FAILED201, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals("哈尼，此单有退货/退款，请先去处理~",
                    orderpostpayrequestcall.getMsg(), "验证msg");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_011() {
        Logger.start(true, "该订单没有补款记录,补款失败");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            Map map = orderService.appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            orderService.orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            orderService.acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price = 1 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(df.format(price));
            String postPayId = orderService.applyForPostPay(orderId, sellerId, payAmount);
            // 删除补款记录
            new DefaultWapper().deleteOrderPostPayByOrderId(orderId);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(payAmount);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.FAILED201, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals(ECode.ErrConditionNotMatch, orderpostpayrequestcall.getString("bcode"), "验证bcode");
            Logger.verifyEquals("此订单无待补款记录.",
                    orderpostpayrequestcall.getMsg(), "验证msg");

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_012() {
        Logger.start(true, "用户可用余额为0,使用账户余额账户");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            Map map = orderService.appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            orderService.orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            orderService.acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price1 = 1 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(df.format(price1));
            String postPayId = orderService.applyForPostPay(orderId, sellerId, payAmount);
            // 支付前账户金额
            DefaultWapper database = new DefaultWapper();
            HashMap<String, Integer> m1 = new HashMap<String, Integer>();
            m1.put("UserId", userId);
            BigDecimal price = (BigDecimal) database.selectAccountInfo(m1).get(0).get("fAvailAmount");
            String accountid = new AccountCallService().getAccountId(userId);
            // 重置用户账户可以余额为 0
            new AccountCallService().resetAccount(accountid, new BigDecimal(0), new BigDecimal(0));
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(payAmount);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("10");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.FAILED201, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals("105", orderpostpayrequestcall.getString("bcode"), "验证bcode");
            Logger.verifyEquals(true,
                    orderpostpayrequestcall.getMsg().contains("账户金额不足"), "验证msg");
            // 重置用户账户
            new AccountCallService().resetAccount(accountid, price, new BigDecimal(0));
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_013() {
        Logger.start(true, "使用账户余额+第三方混合支付,验证第三方支付接口返回报文");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            Map map = orderService.appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            orderService.orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            orderService.acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price1 = 11 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(df.format(price1));
            String postPayId = orderService.applyForPostPay(orderId, sellerId, payAmount);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = BigDecimal.ZERO;
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(payAmount.subtract(new BigDecimal(11)));
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("13");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals("JSON", orderpostpayrequestcall.getData().get("resultType"), "验证code");
            // 验证支付网关返回报文
            verifyAlipayApp(orderId);
        } catch (Exception e) {
            Logger.fail(e);
        }
    }


    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_014() {
        Logger.start(true, "一笔交易里有多个订单,使用账户余额支付");
        try {
            DefaultWapper database = new DefaultWapper();
            OrderCallService orderService = new OrderCallService();
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = placeOrder();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            JSONArray orders = (JSONArray) map.get("orders");
            int tradingId = (Integer) map.get("tradingId");

            int orderId1 = orders.getInt(0);
            int orderId2 = orders.getInt(1);

            // 获取用户需要支付的金额
            // ymt_tradinginfo 表
            BigDecimal needPayAmount = orderService.getNeedPrePayAmountOfCashBymainOrderId(tradingId);
            // 订单主表
            List<Map> ymtOrders = database.selectOrderByOderId(orderId1);
            // 总付款金额
            BigDecimal totalPrice = (BigDecimal) ymtOrders.get(0).get("fTotalPrice");
            // 定金金额
            BigDecimal orderPrice = (BigDecimal) ymtOrders.get(0).get("fOrderPrice");
            // 实际需要补款金额
            BigDecimal needPostPayPrice = totalPrice.subtract(orderPrice);
            // 买家付款
            orderService.orderPayRequest(userId, needPayAmount, tradingId);
            // 接单
            orderService.acceptOrder(orderId1, sellerId);
            // 卖家发起补款
            String postPayId = orderService.applyForPostPay(orderId1, sellerId, needPostPayPrice);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId1);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            // 订单补款金额
            BigDecimal payAmount = needPostPayPrice;
            orderpostpayrequestbean.setUseAccountAmount(payAmount);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("13");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, orderpostpayrequestcall.getCode(), "验证code");
            // 验证数据落地
            verifyDb(tradingId);
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_015() {
        Logger.start(true, "一笔交易里有多个订单,全部使用第三方支付，验证第三方支付接口返回报文");
        try {
            DefaultWapper database = new DefaultWapper();
            OrderCallService orderService = new OrderCallService();
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = placeOrder();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            JSONArray orders = (JSONArray) map.get("orders");
            int tradingId = (Integer) map.get("tradingId");

            int orderId1 = orders.getInt(0);
            int orderId2 = orders.getInt(0);

            // 获取用户需要支付的金额
            // ymt_tradinginfo 表
            List<Map> ymtTradinginfo = database.selectTradinginfoByTradingId(tradingId);
            BigDecimal needPayAmount = (BigDecimal) ymtTradinginfo.get(0).get("fPayableAmount");
            // 订单主表
            List<Map> ymtOrders = database.selectOrderByOderId(orderId1);
            // 调整金额
            BigDecimal discount = (BigDecimal) ymtOrders.get(0).get("fDiscount");
            // 总付款金额
            BigDecimal totalPrice = (BigDecimal) ymtOrders.get(0).get("fTotalPrice");
            // 定金金额
            BigDecimal orderPrice = (BigDecimal) ymtOrders.get(0).get("fOrderPrice");
            // 实际需要补款金额
            BigDecimal needPostPayPrice = totalPrice.subtract(orderPrice);
            // 买家付款
            orderService.orderPayRequest(userId, needPayAmount, tradingId);
            // 接单
            orderService.acceptOrder(orderId1, sellerId);
            // 卖家发起补款
            String postPayId = orderService.applyForPostPay(orderId1, sellerId, needPostPayPrice);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId1);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            // 订单补款金额
            BigDecimal payAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseAccountAmount(payAmount);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("13");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, orderpostpayrequestcall.getCode(), "验证code");
            // 验证数据落地
            verifyAlipayApp(orderId1);
            verifyDb(tradingId);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_016() {
        Logger.start(true, "一笔交易里有多个订单,使用余额+第三方组合支付，验证第三方支付接口返回报文");
        try {
            DefaultWapper database = new DefaultWapper();
            OrderCallService orderService = new OrderCallService();
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = placeOrder();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            JSONArray orders = (JSONArray) map.get("orders");
            int tradingId = (Integer) map.get("tradingId");

            int orderId1 = orders.getInt(0);
            int orderId2 = orders.getInt(0);

            // 获取用户需要支付的金额
            // ymt_tradinginfo 表
            List<Map> ymtTradinginfo = database.selectTradinginfoByTradingId(tradingId);
            BigDecimal needPayAmount = (BigDecimal) ymtTradinginfo.get(0).get("fPayableAmount");
            // 订单主表
            List<Map> ymtOrders = database.selectOrderByOderId(orderId1);
            // 调整金额
            BigDecimal discount = (BigDecimal) ymtOrders.get(0).get("fDiscount");
            // 总付款金额
            BigDecimal totalPrice = (BigDecimal) ymtOrders.get(0).get("fTotalPrice");
            // 定金金额
            BigDecimal orderPrice = (BigDecimal) ymtOrders.get(0).get("fOrderPrice");
            // 实际需要补款金额
            BigDecimal needPostPayPrice = totalPrice.subtract(orderPrice);
            // 买家付款
            orderService.orderPayRequest(userId, needPayAmount, tradingId);
            // 接单
            orderService.acceptOrder(orderId1, sellerId);
            // 卖家发起补款
            String postPayId = orderService.applyForPostPay(orderId1, sellerId, needPostPayPrice);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId1);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            // 订单补款金额
            BigDecimal payAmount = needPostPayPrice.subtract(new BigDecimal(21));
            orderpostpayrequestbean.setUseAccountAmount(payAmount);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("13");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, orderpostpayrequestcall.getCode(), "验证code");
            // 验证数据落地
            verifyAlipayApp(orderId1);
            verifyDb(tradingId);

        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_017() {
        Logger.start(true, "订单支付,校验同步到Mongo数据库");
        try {
            DefaultWapper database = new DefaultWapper();
            OrderCallService orderService = new OrderCallService();
            // 创建订单
            Logger.comment("前置数据准备");
            Map map = placeOrder();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            JSONArray orders = (JSONArray) map.get("orders");
            int tradingId = (Integer) map.get("tradingId");

            int orderId1 = orders.getInt(0);
            int orderId2 = orders.getInt(1);

            // 获取用户需要支付的金额
            // ymt_tradinginfo 表
            List<Map> ymtTradinginfo = database.selectTradinginfoByTradingId(tradingId);
            BigDecimal needPayAmount = (BigDecimal) ymtTradinginfo.get(0).get("fPayableAmount");
            // 订单主表
            List<Map> ymtOrders = database.selectOrderByOderId(orderId1);
            // 调整金额
            BigDecimal discount = (BigDecimal) ymtOrders.get(0).get("fDiscount");
            // 总付款金额
            BigDecimal totalPrice = (BigDecimal) ymtOrders.get(0).get("fTotalPrice");
            // 定金金额
            BigDecimal orderPrice = (BigDecimal) ymtOrders.get(0).get("fOrderPrice");
            // 实际需要补款金额
            BigDecimal needPostPayPrice = totalPrice.subtract(orderPrice);
            // 买家付款
            orderService.orderPayRequest(userId, needPayAmount, tradingId);
            // 接单
            orderService.acceptOrder(orderId1, sellerId);
            // 卖家发起补款
            String postPayId = orderService.applyForPostPay(orderId1, sellerId, needPostPayPrice);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId1);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = new BigDecimal(0);
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            // 订单补款金额
            // BigDecimal payAmount = needPostPayPrice.subtract(new BigDecimal(21));
            orderpostpayrequestbean.setUseAccountAmount(needPostPayPrice);
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("13");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.SUCCESS, orderpostpayrequestcall.getCode(), "验证code");
            // 验证数据落地
            // 检查点
            YMatouSellerOrderWapper sellerorderwapper = new YMatouSellerOrderWapper();
            Map result = null;
            int count = 0;
            // 重试3次
            while (result == null && count < 30) {
                Thread.sleep(1000);
                result = sellerorderwapper.selectOrderInfoById(orderId1, sellerId);
                count++;
            }
            Logger.comment("Mongo中查询出的订单信息:" + result.toString());
            Logger.verifyEquals(orderId1, (Integer) result.get("_id"), "验证OrderId");
            Logger.verifyEquals(sellerId, (Integer) result.get("Seller"), "验证Seller");
            Logger.verifyEquals(userId, (Integer) result.get("Buyer"), "验证Buyer");
            Logger.verifyEquals(17, (Integer) result.get("TradingStatus"), "验证TradingStatus");
            Logger.verifyEquals(1, (Integer) result.get("Type"), "验证Type");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }
    @Test
    @Category(P3.class)
    @TestCase
    public void Tc_OrderPostPayRequest_018() {
        Logger.start(true, "补款使用招行支付,支付失败");
        try {
            // 创建订单
            Logger.comment("前置数据准备");
            OrderCallService orderService = new OrderCallService();
            Map map = orderService.appSaveOrder();
            int orderId = (Integer) map.get("orderId");
            int sellerId = (Integer) map.get("sellerId");
            int userId = (Integer) map.get("userId");
            int tradingId = (Integer) map.get("tradingId");
            DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数
            BigDecimal totalPrice = (BigDecimal) map.get("totalPrice");// 支付金额
            // 买家付款
            orderService.orderPayRequest(userId, totalPrice, tradingId);
            // 接单
            orderService.acceptOrder(orderId, sellerId);
            // 卖家发起补款
            int price1 = 11 + new Random().nextInt(50);
            BigDecimal payAmount = new BigDecimal(df.format(price1));
            String postPayId = orderService.applyForPostPay(orderId, sellerId, payAmount);
            Logger.comment("前置数据准备结束");
            // 参数
            orderpostpayrequestbean.setUserId(userId);
            orderpostpayrequestbean.setOrderId(orderId);
            orderpostpayrequestbean.setTradingPwd("abc123");
            BigDecimal GiftAmount = BigDecimal.ZERO;
            orderpostpayrequestbean.setUseGiftAmount(GiftAmount);
            orderpostpayrequestbean.setBankId("");
            orderpostpayrequestbean.setUserIp("127.0.0.1");
            orderpostpayrequestbean.setMemo("备注");
            orderpostpayrequestbean.setUseAccountAmount(payAmount.subtract(new BigDecimal(11)));
            orderpostpayrequestbean.setCallBackUrl("http://www.baidu.com");
            orderpostpayrequestbean.setUsePlatform(PlatformEnum.SHANGOU_APP.getValue());
            orderpostpayrequestbean.setParamExt("");
            orderpostpayrequestbean.setPayType("50");
            // 发送请求
            orderpostpayrequestcall.setData(orderpostpayrequestbean);
            orderpostpayrequestcall.callService();
            Logger.verifyEquals(ECode.ERROR400, orderpostpayrequestcall.getCode(), "验证code");
            Logger.verifyEquals("100", orderpostpayrequestcall.getBCode(), "验证bcode");
            Logger.verifyEquals("尾款支付不支持该支付渠道!", orderpostpayrequestcall.getMsg(), "验证msg");
        } catch (Exception e) {
            Logger.fail(e);
        }
    }

    private void verifyDb(int tradingId) {
        int orderId = orderpostpayrequestbean.getOrderId();
        // 用户id
        int userId = orderpostpayrequestbean.getUserId();
        // 用户支付的余额
        BigDecimal payAmount = orderpostpayrequestbean.getUseAccountAmount().setScale(2);
        DefaultWapper database = new DefaultWapper();
        // 订单主表
        List<Map> ymtOrders = database.selectOrderByOderId(orderId);
        // 订单商品明细
        List<Map> ymtOrdersInfoList = database.selectOrderInfoByOderId(orderId);
        // ymt_tradinginfo 表
        // List<Map> ymtTradinginfo = database.selectTradinginfoByTradingId(tradingId);
        // ymtOrderState 表
        List<Map> ymtOrderState = database.selectOrderStateByOderId(orderId);
        // ymt_orderpay 表
        List<Map> ymtOrderPay = database.selectOrderPay(orderId);
        // Ymt_OrderPostPay 表
        List<Map> ymtOrderPostPay = database.selectOrderPostPayByOrderId(orderId);
        // 优惠券金额
        BigDecimal couponValue = (BigDecimal) ymtOrders.get(0).get("CouponValue");
        // 商家用户优惠券金额
        BigDecimal sellerCouponValue = (BigDecimal) ymtOrders.get(0).get("fSellerCouponAmount");
        // 平台用户优惠券金额
        BigDecimal ymtCouponValue = (BigDecimal) ymtOrders.get(0).get("fYmtCouponAmount");

        // 申请补款的金额
        BigDecimal postPayAmount = (BigDecimal) ymtOrderPostPay.get(0).get("fAmount");
        // 全款余额支付
        BigDecimal needPayAmount = BigDecimal.ZERO.setScale(2);
        int status = 16;
        if (!(payAmount.compareTo(postPayAmount) == -1)) {
            needPayAmount = payAmount;
            status = 17;
        }
        Logger.comment("验证订单号:" + orderId);
        Logger.comment("验证ymt_order表");
        Logger.verifyEquals(
                status,
                (Integer) ymtOrders.get(0).get("iTradingStatus"), "验证iTradingStatus");

        Logger.comment("验证ymt_orderState表");
        Logger.verifyEquals(1, ymtOrderState.size(), "验证ymt_orderState表");
        Logger.verifyEquals(
                couponValue,
                (BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfCoupon"), "验证fPaidAmountOfCoupon");
        Logger.verifyEquals(
                needPayAmount,
                (BigDecimal) ymtOrderState.get(0).get("fPostPaidAmountOfCash"), "验证fPostPaidAmountOfCash");
        Logger.verifyEquals(
                sellerCouponValue,
                (BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfSellerCoupon"), "验证fPaidAmountOfSellerCoupon");
        Logger.verifyEquals(
                ymtCouponValue,
                (BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfYmtCoupon"), "验证fPaidAmountOfYmtCoupon");
        Logger.verifyEquals(
                (BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfCash"),
                (BigDecimal) ymtOrderState.get(0).get("fPaidAmountOfYmtAccount"), "验证fPaidAmountOfYmtAccount");
    }

    // 一次下单生成2个订单号,分别使用平台,商家优惠券,每个订单下面3个商品
    private Map placeOrder() {
        Map map = new HashMap();
        try {
            PlaceOrderBean placeorderBean = new PlaceOrderBean();
            PlaceOrderCall placeorderCall = new PlaceOrderCall();
            int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
            int sellerId = Integer.valueOf(EnvSetup.getData("SellerId"));
            // 创建产品
            Logger.comment("前置数据准备");
            HashMap<String, Object> productInfo = ProductCallService.createProduct(sellerId, 3);
            Logger.comment("前置数据准备结束");
            String productId = (String) productInfo.get("productId");
            Logger.debug("productId:" + productId);
            String productName = (String) productInfo.get("productName");
            String pic = (String) productInfo.get("pic");
            BigDecimal price = (BigDecimal) (productInfo.get("price"));
            // String catalogId = (String) productInfo.get("catalogId");
            // 买家用户等级
            int userLevel = 3;
            // 订单来源
            int orderSource = OrderSourceEnum.APP.getValue();
            placeorderBean.setOrderSource(orderSource);
            // 终端来源
            int terminalSource = TerminalSourceEnum.IOS.getValue();
            placeorderBean.setTerminalSource(terminalSource);
            // 应用终端来源
            int appTerminalSource = AppTerminalSourceEnum.Phone.getValue();
            placeorderBean.setAppTerminalSource(appTerminalSource);
            // SourceIp
            String sourceIp = "127.0.0.1";
            placeorderBean.setSourceIp(sourceIp);
            // 用户设备号
            String deviceId = "";
            placeorderBean.setDeviceId(deviceId);
            // 订单信息List
            List<OrderInfo> orderInfoList = new ArrayList<OrderInfo>();
            OrderInfo order = new OrderInfo();
            // 订单类型
            int orderType = OrderTypeEnum.Shangou.getValue();
            order.setOrderType(orderType);
            // 卖家
            order.setSellerId(sellerId);
            String leaveWord = "autotest";
            order.setLeaveWord(leaveWord);
            // 运费
            BigDecimal freight = new BigDecimal(23);
            order.setFreight(freight);
            // 优惠券
            // 领用优惠券
            BigDecimal couponValue = new BigDecimal(10);
            // 领用商家优惠券
            String couponCode = new CouponCallService().receiveCouponInfo(sellerId, userId, couponValue);
            order.setCouponCode(couponCode);
            // 优惠券类型
            int couponType = 1;
            order.setCouponUseType(couponType);
            // 优惠券渠道
            int couponChannel = 2;
            order.setCouponChannel(couponChannel);
            // 优惠券金额
            order.setCouponValue(couponValue);
            // 是否全额付款
            boolean isPaidFull = false;
            order.setIsPaidFull(isPaidFull);
            // 收货地址
            String address = "上海市闸北区灵石路636号";
            order.setAddress(address);
            // 邮编
            String postCode = "200001";
            order.setPostCode(postCode);
            // 收件人姓名
            String receieveName = "李四";
            order.setReceieveName(receieveName);
            // 收货人手机号
            String phone = "13100000001";
            order.setPhone(phone);
            // 收货人电话
            String telephone = "021-51002100";
            order.setTelephone(telephone);
            // 自动取消小时数
            BigDecimal autoCancelOrderHours = new BigDecimal(10);
            order.setAutoCancelOrderHours(autoCancelOrderHours);
            // 订单商品信息
            List<OrderProductInfo> orderProductInfoList = new ArrayList<OrderProductInfo>();
            OrderProductInfo productinfo = new OrderProductInfo();
            OrderProductInfo productinfo2 = new OrderProductInfo();
            OrderProductInfo productinfo3 = new OrderProductInfo();
            // 商品id
            productinfo.setProductId(productId);
            // 商品名称
            productinfo.setProductName(productName);
            // 商品规格id
            String catalogId = TestDataManager.getRandomUUID().toString();
            productinfo.setCatalogId(catalogId);
            // 备货状态(1-现货 2-代购 3-FBX)
            int catalogType = StockStatusEnum.Spot.getValue();
            productinfo.setStockStatusEnum(catalogType);
            // 商品数量
            int productNum = 1 + new Random().nextInt(5);
            productinfo.setProductNum(productNum);
            // 商品一级目录id
            int firstCategoryId = 1;
            productinfo.setFirstCategoryId(firstCategoryId);
            // 商品一级目录id
            int secondCategoryId = 2;
            productinfo.setSecondCategoryId(secondCategoryId);
            // 商品一级目录id
            int thirdCategoryId = 3;
            productinfo.setThirdCategoryId(thirdCategoryId);
            // 商品品牌id
            int brandId = 5;
            productinfo.setBrandId(brandId);
            // 商品url
            productinfo.setPictureUrl(pic);
            // 商品属性信息(按JSON格式存储，如--颜色:黑色,尺寸:XXS)
            String propetyInfo = "";
            productinfo.setPropetyInfo(propetyInfo);
            // 商品价格
            BigDecimal productPrice = price;
            productinfo.setProductPrice(productPrice);
            // 商品预付定金价格
            BigDecimal earnestPrice = price.divide(new BigDecimal(3), 2, BigDecimal.ROUND_HALF_UP); // 小数点后保留2位并四舍五入
            productinfo.setEarnestPrice(earnestPrice);
            // 价格类型
            int priceType = PriceTypeEnum.Unkown.getValue();
            productinfo.setPriceType(priceType);
            // 买家或卖家承担关税(0-卖家承担 1-买家承担)
            int tariffType = 0;
            productinfo.setTariffType(tariffType);
            // 物流类型
            int logisticsType = LogisticsTypeEnum.SailProtect.getValue();
            productinfo.setLogisticsType(logisticsType);
            // 保税区
            int bondedArea = BondedAreaEnum.NingBo.getValue();
            productinfo.setBondedArea(bondedArea);
            // 商品备案号
            String productRecordNo = "123456";
            productinfo.setProductRecordNo(productRecordNo);
            // SKU
            String sku = "1234567";
            productinfo.setSKU(sku);
            // 套餐编号
            String packageNo = "11111111";
            productinfo.setPackageNo(packageNo);
            // 商品退货渠道
            int productRefundChannel = ProductRefundChannelEnum.Official.getValue();
            productinfo.setProductRefundChannel(productRefundChannel);
            // 商品信息(存储格式为：Json格式)
            String productDetailInfo =
                    "e5a1eccf-6a14-458f-b907-35dc9a3d2713#适用人群:b13e9eb1-98d6-4d39-8c35-225758e443d3#男";
            productinfo.setProductDetailInfo(productDetailInfo);
            // 活动商品信息
            ProductActivityInfo activityInfo = new ProductActivityInfo();
            // 商品活动号
            int activityId = 46870;
            activityInfo.setActivityId(activityId);
            // 额外费用
            BigDecimal premium = new BigDecimal(10);
            activityInfo.setPremium(premium);
            // 是否算入成本价
            boolean isCost = false;
            activityInfo.setIsCost(isCost);
            // 是否使用优惠券
            boolean isUseCoupon = false;
            activityInfo.setIsUseCoupon(isUseCoupon);
            // 是否免佣金
            boolean isFeeFree = false;
            activityInfo.setIsFeeFree(isFeeFree);
            // 活动开始时间
            String beginDate = YMTDateUtil.getBeforeOrNextDay(-100);
            activityInfo.setActivityBeginDate(beginDate);
            // 活动结束时间
            String endDate = YMTDateUtil.getBeforeOrNextDay(10);
            activityInfo.setActivityEndDate(endDate);
            // 商品活动模板号
            int activityTemplateId = 987654;
            activityInfo.setActivityTemplateId(activityTemplateId);
            // 商品活动促销类型
            int promotionType = ActivityPromotionTypeEnum.DiscountPrice.getValue();
            activityInfo.setPromotionType(promotionType);
            // 促销价格
            BigDecimal promotionPrice = new BigDecimal(1);
            activityInfo.setPromotionPrice(promotionPrice);
            // 促销价格
            BigDecimal commissionRate = new BigDecimal(0);
            activityInfo.setCommissionRate(commissionRate);
            productinfo.setActivityInfo(activityInfo);
            // 第二件商品
            // 商品id
            productinfo2.setProductId(productId);
            // 商品名称
            productinfo2.setProductName(productName);
            // 商品规格id
            String catalogId2 = TestDataManager.getRandomUUID().toString();
            productinfo2.setCatalogId(catalogId2);
            // 备货状态(1-现货 2-代购 3-FBX)
            int catalogType2 = StockStatusEnum.Spot.getValue();
            productinfo2.setStockStatusEnum(catalogType2);
            // 商品数量
            int productNum2 = 1 + new Random().nextInt(5);
            productinfo2.setProductNum(productNum2);
            // 商品一级目录id
            int firstCategoryId2 = 1;
            productinfo2.setFirstCategoryId(firstCategoryId2);
            // 商品一级目录id
            int secondCategoryId2 = 2;
            productinfo2.setSecondCategoryId(secondCategoryId2);
            // 商品一级目录id
            int thirdCategoryId2 = 3;
            productinfo2.setThirdCategoryId(thirdCategoryId2);
            // 商品品牌id
            int brandId2 = 3;
            productinfo2.setBrandId(brandId2);
            // 商品url
            productinfo2.setPictureUrl(pic);
            // 商品属性信息(按JSON格式存储，如--颜色:黑色,尺寸:XXS)
            String propetyInfo2 = "";
            productinfo2.setPropetyInfo(propetyInfo2);
            // 商品价格
            BigDecimal productPrice2 = price;
            productinfo2.setProductPrice(productPrice2);
            // 商品预付定金价格
            BigDecimal earnestPrice2 = price.divide(new BigDecimal(3), 2, BigDecimal.ROUND_HALF_UP); // 小数点后保留2位并四舍五入
            productinfo2.setEarnestPrice(earnestPrice2);
            // 价格类型
            int priceType2 = PriceTypeEnum.NewPersonPrice.getValue();
            productinfo2.setPriceType(priceType2);
            // 买家或卖家承担关税(0-卖家承担 1-买家承担)
            int tariffType2 = 0;
            productinfo2.setTariffType(tariffType2);
            // 物流类型
            int logisticsType2 = LogisticsTypeEnum.XloboBondedDelivery.getValue();
            productinfo2.setLogisticsType(logisticsType2);
            // 保税区
            int bondedArea2 = BondedAreaEnum.NingBo.getValue();
            productinfo2.setBondedArea(bondedArea2);
            // 商品备案号
            String productRecordNo2 = "123456";
            productinfo2.setProductRecordNo(productRecordNo2);
            // SKU
            String sku2 = "1234567";
            productinfo2.setSKU(sku2);
            // 套餐编号
            String packageNo2 = "11111111";
            productinfo2.setPackageNo(packageNo2);
            // 商品退货渠道
            int productRefundChannel2 = ProductRefundChannelEnum.Official.getValue();
            productinfo2.setProductRefundChannel(productRefundChannel2);
            // 商品信息(存储格式为：Json格式)
            String productDetailInfo2 =
                    "e5a1eccf-6a14-458f-b907-35dc9a3d2713#适用人群:b13e9eb1-98d6-4d39-8c35-225758e443d3#男";
            productinfo2.setProductDetailInfo(productDetailInfo2);
            productinfo2.setActivityInfo(activityInfo);
            // 第三件商品
            // 商品id
            productinfo3.setProductId(productId);
            // 商品名称
            productinfo3.setProductName(productName);
            // 商品规格id
            String catalogId3 = TestDataManager.getRandomUUID().toString();
            productinfo3.setCatalogId(catalogId3);
            // 备货状态(1-现货 2-代购 3-FBX)
            productinfo3.setStockStatusEnum(catalogType);
            // 商品数量
            int productNum3 = 1 + new Random().nextInt(5);
            productinfo3.setProductNum(productNum3);
            // 商品一级目录id
            productinfo3.setFirstCategoryId(firstCategoryId);
            // 商品一级目录id
            productinfo3.setSecondCategoryId(secondCategoryId);
            // 商品一级目录id
            productinfo3.setThirdCategoryId(thirdCategoryId);
            // 商品品牌id
            int brandId3 = 3;
            productinfo3.setBrandId(brandId3);
            // 商品url
            productinfo3.setPictureUrl(pic);
            // 商品属性信息(按JSON格式存储，如--颜色:黑色,尺寸:XXS)
            String propetyInfo3 = "";
            productinfo3.setPropetyInfo(propetyInfo3);
            // 商品价格
            BigDecimal productPrice3 = price;
            productinfo3.setProductPrice(productPrice3);
            // 商品预付定金价格
            BigDecimal earnestPrice3 = price.divide(new BigDecimal(3), 2, BigDecimal.ROUND_HALF_UP); // 小数点后保留2位并四舍五入
            productinfo3.setEarnestPrice(earnestPrice3);
            // 价格类型
            int priceType3 = PriceTypeEnum.NewPersonPrice.getValue();
            productinfo3.setPriceType(priceType3);
            // 买家或卖家承担关税(0-卖家承担 1-买家承担)
            int tariffType3 = 0;
            productinfo3.setTariffType(tariffType3);
            // 物流类型
            int logisticsType3 = LogisticsTypeEnum.XloboBondedDelivery.getValue();
            productinfo3.setLogisticsType(logisticsType3);
            // 保税区
            int bondedArea3 = BondedAreaEnum.NingBo.getValue();
            productinfo3.setBondedArea(bondedArea3);
            // 商品备案号
            productinfo3.setProductRecordNo(productRecordNo);
            // SKU
            productinfo3.setSKU(sku);
            // 套餐编号
            productinfo3.setPackageNo(packageNo);
            // 商品退货渠道
            productinfo3.setProductRefundChannel(productRefundChannel);
            // 商品信息(存储格式为：Json格式)
            productinfo3.setProductDetailInfo(productDetailInfo);
            // 活动商品信息
            productinfo3.setActivityInfo(activityInfo);

            orderProductInfoList.add(productinfo);
            orderProductInfoList.add(productinfo2);
            orderProductInfoList.add(productinfo3);
            // 订单商品信息
            order.setOrderProductInfoList(orderProductInfoList);
            // 第二个订单
            OrderInfo order2 = new OrderInfo();
            // 订单类型
            int orderType2 = OrderTypeEnum.Shangou.getValue();
            order2.setOrderType(orderType2);
            // 卖家
            order2.setSellerId(sellerId);
            String leaveWord2 = "autotest";
            order2.setLeaveWord(leaveWord2);
            // 运费
            BigDecimal freight2 = new BigDecimal(20);
            order2.setFreight(freight2);
            // 优惠券
            BigDecimal couponValue2 = new BigDecimal(11);
            // ymt 平台优惠券
            String couponCode2 = new OrderCallService().receivePlatformCoupon(userId, couponValue);
            order2.setCouponCode(couponCode2);
            // 优惠券类型
            int couponType2 = 1;
            order2.setCouponUseType(couponType2);
            // 优惠券渠道 1 ymt平台，2 商家
            int couponChannel2 = 1;
            order2.setCouponChannel(couponChannel2);
            // 优惠券金额
            order2.setCouponValue(couponValue2);
            // 是否全额付款
            boolean isPaidFull2 = false;
            order2.setIsPaidFull(isPaidFull2);
            // 收货地址
            String address2 = "上海市闸北区灵石路636号";
            order2.setAddress(address2);
            // 邮编
            String postCode2 = "200001";
            order2.setPostCode(postCode2);
            // 收件人姓名
            String receieveName2 = "李四";
            order2.setReceieveName(receieveName2);
            // 收货人手机号
            String phone2 = "13100000002";
            order2.setPhone(phone2);
            // 收货人电话
            String telephone2 = "021-51002111";
            order2.setTelephone(telephone2);
            // 自动取消小时数
            BigDecimal autoCancelOrderHours2 = new BigDecimal(2);
            order2.setAutoCancelOrderHours(autoCancelOrderHours2);
            // 订单商品信息 拷贝第一单3个商品
            order2.setOrderProductInfoList(orderProductInfoList);
            // 订单信息
            orderInfoList.add(order);
            // 订单信息
            orderInfoList.add(order2);
            placeorderBean.setUserId(userId);
            placeorderBean.setOrderInfoList(orderInfoList);
            placeorderCall.setData(placeorderBean);
            placeorderCall.callService();
            JSONArray orders = placeorderCall.getOrderIds();
            int tradingId = placeorderCall.getTradingId();
            map.put("orders", orders);
            map.put("tradingId", tradingId);
        } catch (Exception e) {
            Logger.fail(e);
        }
        return map;
    }
}
